package com.li.bottom;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ndboo.reslibrary.R;

/**
 * Author: Li
 * Date: 2017/8/7
 * Description:
 */


public class BottomNavigationItem extends LinearLayout {
    private ImageView mImgTab;

    public TextView getTxtTab() {
        return mTxtTab;
    }

    private TextView mTxtTab;
    private int mSrc;
    private String mText;

    private ColorStateList mStateList;
    public BottomNavigationItem(Context context) {
        super(context,null);
    }

    public BottomNavigationItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        View view = LayoutInflater.from(context)
                .inflate(R.layout.tab_bottom_view, this);
        mImgTab = (ImageView) view.findViewById(R.id.img_tab);
        mTxtTab = (TextView) view.findViewById(R.id.txt_tab);

        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.BottomNavigationItem);
        mSrc = array.getResourceId(R.styleable.BottomNavigationItem_src,-1);
        mText = array.getString(R.styleable.BottomNavigationItem_txt);
        mStateList=array.getColorStateList(R.styleable.BottomNavigationItem_stateList);
        array.recycle();
        mImgTab.setImageDrawable(
                ContextCompat.getDrawable(context,mSrc)
        );
        if (mStateList != null) {
            mTxtTab.setTextColor(mStateList);
        }
        mTxtTab.setText(mText);
    }

}
